package br.com.linkideias.model.command.ideiapcc;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import br.com.linkideias.model.bean.Categoria;
import br.com.linkideias.model.bean.Empresa;
import br.com.linkideias.model.bean.Estatus;
import br.com.linkideias.model.bean.IdeiaPcc;
import br.com.linkideias.model.command.InterfaceCommand;
import br.com.linkideias.model.dao.HibernateDAO;
import br.com.linkideias.model.dao.InterfaceDAO;
import br.com.linkideias.util.HibernateUtil;

public class ConsultarIdeiaPcc implements InterfaceCommand {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		
		Empresa empresa = null;

		
		InterfaceDAO<Estatus> estatusDAO = new HibernateDAO<Estatus>(Estatus.class, (Session)request.getAttribute(HibernateUtil.HIBERNATE_SESSION));
		request.getSession().setAttribute("estatuses", estatusDAO.getBeans());
		InterfaceDAO<Categoria> categoriaDAO = new HibernateDAO<Categoria>(Categoria.class, (Session)request.getAttribute(HibernateUtil.HIBERNATE_SESSION));
		request.getSession().setAttribute("categorias", categoriaDAO.getBeans());
		
		InterfaceDAO<IdeiaPcc> ideiaPccDAO = new HibernateDAO<IdeiaPcc>(IdeiaPcc.class, (Session)request.getAttribute(HibernateUtil.HIBERNATE_SESSION));
		empresa = (Empresa) request.getSession().getAttribute("empresa");
		System.out.println(empresa.getNome());
		
		List<IdeiaPcc> ideiaPccs= ideiaPccDAO.getIdeiaPccEmpresa(empresa);
		
		for(IdeiaPcc p: ideiaPccs){
			System.out.println(p.getNome());
		}
		request.setAttribute("ideiaPccs", ideiaPccs);
		return "empresaIdeiaPcc.jsp";
	}
}